package org.example.leetcode;

import org.example.algo.N05_SingleLinked;

import java.util.List;

/**
 * K 个一组翻转链表
 *
 * @author shenguangyang
 */
public class N025_ReverseKGroup {
    ListNode head;
    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public void addLast(ListNode node) {
        if (this.head == null) {
            this.head = node;
            return;
        }

        ListNode cur = head;
        while (cur.next != null) {
            cur = cur.next;
        }
        cur.next = node;
    }

    public void reverse(ListNode head, ListNode tail) {
        if (head == null || tail == null) {
            return;
        }
        ListNode cur = head;
        ListNode curNext;
        ListNode pre = null;
        while (cur != null) {
            curNext = cur.next;
            cur.next = pre;
            pre = cur;
            cur = curNext;
            if (cur == tail) {
                break;
            }
        }
        head.next = tail;
    }

    public ListNode reverseKGroup(ListNode head, int k) {
        return null;
    }

}
